<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>博文发布</title>
  <!--  公共头部-->
  <div th:replace="admin/common :: head"></div>
  <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css" th:href="@{/lib/editormd/css/editormd.min.css}">
</head>
<body>


<!--公共导航-->
<div th:replace="admin/common :: menu(1)"></div>

  <div class="m-padded-tb-hugex">
  <div class="ui attached pointing menu">
    <div class="ui container">
      <div class="right menu">
        <a href="#" class="teal active item">新增</a>
        <a href="#" th:href="@{/admin/blog}" class="item">列表</a>
      </div>
    </div>
  </div>
  </div>

  <!--中间内容-->
  <div  class="">
    <div class="ui container">
      <form id="blog-form" action="#" th:action="@{/admin/blogs}" method="post" class="ui form">
        <input type="hidden" name="publish">
        <input type="hidden" name="id">

        <div class="required field">
          <div class="ui left labeled input">
            <div class="ui selection compact teal basic dropdown label">
              <input type="hidden" value="原创" name="flag">
              <i class="dropdown icon"></i>
              <div class="text">原创</div>
              <div class="menu">
                <div class="item" data-value="原创">原创</div>
                <div class="item" data-value="转载">转载</div>
                <div class="item" data-value="翻译">翻译</div>
              </div>
            </div>
            <input type="text" name="title" placeholder="标题">
          </div>
        </div>

        <div class="required field">
          <div class="" id="md-content" style="z-index: 1 !important;">
            <textarea placeholder="博客内容" name="content" style="display: none" ></textarea>
          </div>
        </div>

        <div class="two fields">
          <div class="required field">
            <div class="ui left labeled action input">
              <label class="ui compact teal basic label">分类</label>
              <div class="ui fluid selection dropdown">
                <!--新增-->
                <input type="hidden" name="type.typesId" >
                <!--编辑-->
                <input type="hidden" name="typesId" >
                <i class="dropdown icon"></i>
                <div class="default text">分类</div>
                <div class="menu">
                  <div class="item" th:each="type:${types}" th:data-value="${type.typesId}" th:text="${type.typesName}" data-value="1">我的故事</div>
                </div>
              </div>
            </div>
          </div>

          <div class="required field">
            <div class="ui left labeled input">
              <label class="ui teal basic label">首图</label>
              <input type="text" name="img" placeholder="首图引用地址">
            </div>
          </div>
        </div>

        <div class="required field">
          <textarea name="description" placeholder="博客描述..." maxlength="200"></textarea>
        </div>

        <div class="inline fields">
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="recommend_open" name="recommend_open" checked class="hidden">
              <label for="recommend_open">推荐</label>
            </div>
          </div>
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="share_open" name="share_open" class="hidden">
              <label for="share_open">转载声明</label>
            </div>
          </div>
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="money_open" name="money_open" class="hidden">
              <label for="money_open">赞赏</label>
            </div>
          </div>
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="comment_open" name="comment_open" class="hidden">
              <label for="comment_open">评论</label>
            </div>
          </div>
        </div>

        <div class="ui error message"></div>

        <div class="ui right aligned container">
          <button type="button" class="ui button" onclick="window.history.go(-1)" >返回</button>
          <button type="button" id="save-btn" class="ui secondary button">保存</button>
          <button type="button" id="publish-btn" class="ui teal button">发布</button>
        </div>

      </form>
    </div>
  </div>

  <br>
  <br>
<!--公共底部栏-->
<div th:replace="admin/common :: #footer"></div>


<!--公共js-->
<div th:replace="admin/common :: #js"></div>
<script src="../../static/lib/editormd/editormd.min.js" th:src="@{/lib/editormd/editormd.min.js}"></script>


  <script>
    //初始化Markdown编辑器
    var contentEditor;
    $(function() {
      contentEditor = editormd("md-content", {//这里是使用书写内容模块的id
        width   : "100%",
        height  : 640,
        syncScrolling : "single",
        path    : "/lib/editormd/lib/",//这里是editor/lib的目录
        saveHTMLToTextarea : true,//方便表单提交
        // theme: "dark",//工具栏主题
        // previewTheme: "dark",//预览主题
        // editorTheme: "pastel-on-dark",//编辑主题
        tocm: true,//用tocm
        tex: true,//数学公式开启
        flowChart: true,//开启流程图
        sequenceDiagram: true,//时序、序列图开启

        /**上传图片相关配置*/
        imageUpload : true,  //开启图片上传
        imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],//支持格式
        imageUploadURL : "/img/imgUpload", //上传的路径，就是controller路径
      });
    });





















    $('.menu.toggle').click(function () {
      $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
      on : 'hover'
    });

    $('#save-btn').click(function () {
      $('[name="publish"]').val(false);
      $('#blog-form').submit();
    });


    $('#publish-btn').click(function () {
      $('[name="publish"]').val(true);
      $('#blog-form').submit();
    });



    $('.ui.form').form({
      fields : {
        title : {
          identifier: 'title',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客标题'
          }]
        },
        content : {
          identifier: 'content',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客内容'
          }]
        },
        typeId : {
          identifier: 'type.typesId',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客分类'
          }]
        },
        firstPicture : {
          identifier: 'img',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客首图'
          }]
        },
        description : {
          identifier: 'description',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客描述'
          }]
        }
      }
    });

  </script>
</body>
</html>